package cn.com.generaldata.os.report.xml;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.com.generaldata.os.pojo.mvc.Report;
import cn.com.generaldata.os.pojo.mvc.Row;
import cn.com.generaldata.os.util.XMLComplexityIntf;
import cn.com.generaldata.os.util.XMLUtil;

public class ReportExporter {
	private static Log log = LogFactory.getLog(ReportExporter.class);
	private static final String log_header = "[Report][Exporter]";

	public static boolean exportReport(Report report, String fileName) {
		try {
			if (null == report) {
				log.error(log_header + "[exportReport]report is null");
				return Boolean.FALSE;
			}
			if (null == fileName || fileName.trim().length() == 0) {
				log.error(log_header + "[exportReport]fileName is null");
				return Boolean.FALSE;
			}

			XMLUtil.writeToXMLFile(report, fileName, new XMLComplexityIntf() {

				@SuppressWarnings("rawtypes")
				@Override
				public Map<String, Class> generateAliasMap() {
					Map<String, Class> map = new HashMap<String, Class>();
					map.put("Report", Report.class);
					map.put("Row", Row.class);
					return map;
				}

			});

			return Boolean.TRUE;
		} catch (Exception ex) {
			log.error(log_header + "[exportReport]Exception: ", ex);
			return Boolean.FALSE;
		}
	}
}
